package com.exchange.controller.app.otc;

import java.math.BigDecimal;
import java.util.List;

import com.exchange.controller.BaseController;
import com.exchange.interceptor.AppUserTokenInterceptor;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;

/**
 * OTC
 */
@Before({OTCVaidator.class,AppUserTokenInterceptor.class})
public class OTCController extends BaseController {
	
	@Inject
	OTCService service;
	
	/** 商户申请相关 **/
	/**
	 * 申请成为商户
	 */
	public void apply(String nickName, String reason){
		Ret ret = service.apply(getAttr("user"), nickName, reason);
		renderJson(ret);
    }
	/**
	 * 获取当前用户商户详情.申请情况
	 */
	public void details(){
		Ret ret = service.details(getAttr("user"));
		renderJson(ret);
    }
	
	
	/** 商户信任相关 **/
	/**
     * 当前用户信任管理 - 信任我的/我信任的/我屏蔽的
     */
    public void UserTrustQuery(Integer trustType, Integer pageNumber) {
    	Ret ret = service.UserTrustQuery(getAttr("user"), trustType, pageNumber);
    	renderJson(ret);
    }
    /**
     * 添加 | 取消（信任/屏蔽用户 | 举报广告）
     */
    public void SetTrust(Integer event, Integer advertId, Integer passiveUserId, Integer type, Integer trustId, String reason, String content) {
    	Ret ret = service.SetTrust(getAttr("user"), event, advertId, passiveUserId, type, trustId, reason, content);
    	renderJson(ret);
    }
    
    
    /** otc广告相关 **/
    /**
     * 我的广告
     */
    public void myOtcAdverts(Integer state, Integer pageNumber){
    	Ret ret = service.myOtcAdverts(getAttr("user"), state, pageNumber);
    	renderJson(ret);
    }
    /**
     * 获取广告详情
     */
    public void advertDetail(Integer advertId){
    	Ret ret = service.advertDetail(advertId);
    	renderJson(ret);
    }
    /**
     * 发布广告,更改. type:买false，卖true  payType:wepy,ali,paypay格式
     */
    public void advertModify(Integer event, Boolean type, String legalCurrency, String payTypes, String coin, BigDecimal price, BigDecimal limitDown, BigDecimal limitUp, String remark, Integer advertId){
    	Ret ret = service.advertModify(getAttr("user"), event, type, legalCurrency, payTypes, coin, price, limitDown, limitUp, remark, advertId);
    	renderJson(ret);
    }
    /**
     * 下架广告
     */
    public void advertInvalid(Integer advertId){
    	Ret ret = service.advertInvalid(getAttr("user"), advertId);
    	renderJson(ret);
    }
    /**
     * 获取出售/买入的广告列表
     */
    public void advertList(Integer pageNumber, Boolean type, String coin, String payType, String legalCurrency){
    	Ret ret = service.advertList(pageNumber, type, coin, payType, legalCurrency);
    	renderJson(ret);
    }
    
    
    /** OTC订单管理相关 **/
    /**
     * 当前用户OTC订单列表
     */
    public void otcOrderquery(Integer pageNumber, Boolean type, Integer state) {
    	Ret ret = service.otcOrderquery(getAttr("user"), pageNumber, type, state);
    	renderJson(ret);
    }
    /**
     * 用户看到买入的广告,需要将自己的卖币给他, payType前端选择一种
     */
    public void otcSell(Integer advertId, Boolean type, BigDecimal amount, BigDecimal num, String payType) {
    	Ret ret = service.otcSell(getAttr("user"), advertId, type, amount, num, payType);
    	renderJson(ret);
    }
    /**
     * 买入币
     */
    public void otcBuy(Integer advertId, Boolean type, BigDecimal amount, BigDecimal num, String payType) {
    	Ret ret = service.otcBuy(getAttr("user"), advertId, type, amount, num, payType);
    	renderJson(ret);
    }
    /**
     * 取消otc订单,订单只能是要付钱的一方撤销
     */
    public void cancelOtcOrder(Integer otcOrderId) {
    	Ret ret = service.cancelOtcOrder(getAttr("user"), otcOrderId);
    	renderJson(ret);
    }
    /**
     * 用户点击已打款,在放币操作之前
     */
    public void isPay(Integer otcOrderId) {
    	Ret ret = service.isPay(getAttr("user"), otcOrderId);
    	renderJson(ret);
    }
    /**
     * 放币,交易成功后需要流水,和手续计算,必须给了钱之后才能放币操作
     */
    public void otcAdopt(Integer otcOrderId) {
    	Ret ret = service.otcAdopt(getAttr("user"), otcOrderId);
    	renderJson(ret);
    }
    /**
     * 评论/打分 ,satisfaction:（1不满意，2一般，3不满意）,opinion:内容
     */
    public void otcComment(Integer otcOrderId, String opinion, Integer satisfaction) {
    	Ret ret = service.otcComment(getAttr("user"), otcOrderId, opinion, satisfaction);
    	renderJson(ret);
    }
    /**
     * 订单申述
     */
    public void otcRepresentation(List<UploadFile> materials, String orderNumber, Integer type, String reason) {
    	Ret ret = service.otcRepresentation(getAttr("user"), orderNumber, type, reason, materials);
    	renderJson(ret);
    }
    /**
     * 获取订单详情
     */
    public void otcOrderDetails(Integer otcOrderId) {
    	Ret ret = service.otcOrderDetails(getAttr("user"), otcOrderId);
    	renderJson(ret);
    }
    
    
    
    
	
}
